<template>
  <button
    :class="[
      'tech-button',
      `tech-button--${type}`,
      `tech-button--${size}`,
      {
        'tech-button--block': block,
        'tech-button--loading': loading,
        'tech-button--disabled': disabled || loading,
      },
    ]"
    :disabled="disabled || loading"
    @click="handleClick"
  >
    <div v-if="loading" class="tech-button__spinner"></div>
    <slot v-else />
  </button>
</template>

<script setup lang="ts">
interface ButtonProps {
  type?: "primary" | "secondary" | "danger" | "ghost";
  size?: "small" | "medium" | "large";
  block?: boolean;
  loading?: boolean;
  disabled?: boolean;
}

const props = withDefaults(defineProps<ButtonProps>(), {
  type: "primary",
  size: "medium",
  block: false,
  loading: false,
  disabled: false,
});

const emit = defineEmits(["click"]);

const handleClick = (event: MouseEvent) => {
  if (!props.disabled && !props.loading) {
    emit("click", event);
  }
};
</script>

<style scoped>
.tech-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  outline: none;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  white-space: nowrap;
  vertical-align: middle;
  user-select: none;
  margin-bottom: 10px;
}

/* 不同类型按钮样式 */
.tech-button--primary {
  background-color: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(0, 240, 255, 0.3);
}

.tech-button--primary:hover:not(.tech-button--disabled) {
  background-color: var(--accent-dark);
  border-color: var(--accent-dark);
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.6);
  filter: brightness(1.2);
}

.tech-button--secondary {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--accent-dark);
}

.tech-button--secondary:hover:not(.tech-button--disabled) {
  background-color: var(--bg-primary);
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(0, 240, 255, 0.3);
}

.tech-button--danger {
  background-color: #ff4d4f;
  color: white;
  border-color: #ff4d4f;
}

.tech-button--danger:hover:not(.tech-button--disabled) {
  background-color: #d9363e;
  border-color: #d9363e;
  box-shadow: 0 0 8px rgba(255, 77, 79, 0.3);
}

.tech-button--ghost {
  background-color: transparent;
  color: var(--accent);
  border-color: var(--accent);
}

.tech-button--ghost:hover:not(.tech-button--disabled) {
  background-color: rgba(0, 240, 255, 0.1);
  box-shadow: 0 0 8px rgba(0, 240, 255, 0.3);
}

/* 不同尺寸按钮样式 */
.tech-button--small {
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
  height: 2rem;
}

.tech-button--medium {
  padding: 0.5rem 1rem;
  font-size: 1rem;
  height: 2.5rem;
}

.tech-button--large {
  padding: 0.75rem 1.5rem;
  font-size: 1.125rem;
  height: 3rem;
}

/* 块级按钮 */
.tech-button--block {
  display: flex;
  width: 100%;
}

/* 禁用状态 */
.tech-button--disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

/* 加载状态 */
.tech-button--loading {
  cursor: not-allowed;
}

.tech-button__spinner {
  width: 16px;
  height: 16px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* 按钮焦点状态 */
.tech-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
</style>
